package com.mes.cloud.web;

import com.mes.cloud.api.dto.request.role.BindMenuRequest;
import com.mes.cloud.api.dto.request.role.MenuListRequest;
import com.mes.cloud.api.dto.request.role.RolePidListRequest;
import com.mes.cloud.api.dto.response.role.RoleMenuDto;
import com.mes.cloud.common.JsonResult;
import com.mes.cloud.service.SysRoleMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.Set;

/**
 * @Description TODO
 * @author: wxm
 * @date: 2019/8/6 9:53
 * @version: 1.0
 */
@Api(tags = "角色菜单业务", value = "角色菜单业务")
@RestController
@RequestMapping(value = "/sysRoleMenu")
public class SysRoleMenuController {

    private SysRoleMenuService sysRoleMenuService;

    @Autowired
    public SysRoleMenuController(SysRoleMenuService sysRoleMenuService) {
        this.sysRoleMenuService = sysRoleMenuService;
    }

    /**
     * 功能: 查看角色拥有的菜单
     *
     * @param menuListRequest
     * @return JsonResult<List<RoleMenuDto>>
     */
    @ApiOperation(value = "查看角色拥有的菜单", notes = "查看角色拥有的菜单")
    @PostMapping(value = "/menuList")
    public JsonResult<List<RoleMenuDto>> menuList(@Valid @RequestBody MenuListRequest menuListRequest) {
        return sysRoleMenuService.menuList(menuListRequest);
    }

    /**
     * 功能: 获取角色下某个节点的菜单
     *
     * @param rolePidListRequest
     * @return JsonResult<List<RoleMenuDto>>
     */
    @ApiOperation(value = "获取角色下某个节点的菜单", notes = "获取角色下某个节点的菜单")
    @PostMapping(value = "/rolePidList")
    public JsonResult<List<RoleMenuDto>> rolePidList(@Valid @RequestBody RolePidListRequest rolePidListRequest) {
        return sysRoleMenuService.rolePidList(rolePidListRequest);
    }

    /**
     * 功能: 查看遴选角色的权限url
     *
     * @return JsonResult<Set<String>>
     */
    @ApiOperation(value = "查看遴选角色的权限url", notes = "查看遴选角色的权限url")
    @PostMapping(value = "/getCullingAuthUrl")
    public JsonResult<Set<String>> getCullingAuthUrl() {
        return sysRoleMenuService.getCullingAuthUrl();
    }

    /**
     * 功能: 角色绑定菜单
     *
     * @param bindMenuRequest
     * @return JsonResult
     */
    @ApiOperation(value = "角色绑定菜单", notes = "角色绑定菜单")
    @PostMapping(value = "/bindMenu")
    public JsonResult bindMenu(@Valid @RequestBody BindMenuRequest bindMenuRequest) {
        return sysRoleMenuService.bindMenu(bindMenuRequest);
    }

    /**
     * 功能: 角色绑定菜单
     *
     * @param bindMenuRequest
     * @return JsonResult
     */
    @ApiOperation(value = "角色绑定菜单", notes = "角色绑定菜单")
    @PostMapping(value = "/bindMenuNew")
    public JsonResult bindMenuNew(@Valid @RequestBody  BindMenuRequest bindMenuRequest) {
        return sysRoleMenuService.bindMenuNew(bindMenuRequest);
    }
}
